package com.rajaev.dtu.tractor.app.processor;

import com.rajaev.dtu.tractor.domain.entity.BatteryPo;
import com.rajaev.dtu.tractor.domain.entity.Protocol485Dto;
import com.rajaev.dtu.tractor.domain.entity.SnotiMessage;

public class SnotiMessageContextHolder {

    private static ThreadLocal<SnotiMessageContext> context = new ThreadLocal<>();

    public static void clear() {
        context.remove();
    }

    public static void initContext(BatteryPo batteryPo, SnotiMessage snotiMessage) {
        SnotiMessageContext snotiMessageContext = new SnotiMessageContext();
        snotiMessageContext.setSnotiMessage(snotiMessage);
        snotiMessageContext.setBatteryPo(batteryPo);
        snotiMessageContext.setBatteryId(batteryPo.getId());
        context.set(snotiMessageContext);
    }

    public static SnotiMessageContext getContext() {
        return context.get();
    }

    public static SnotiMessage getSnotiMessage() {
        return context.get().getSnotiMessage();
    }

    public static BatteryPo getTargetBattery() {
        return context.get().getBatteryPo();
    }

    public static void setDeviceMonitorInfo(Protocol485Dto protocol485Dto) {
        context.get().setProtocol485Dto(protocol485Dto);
    }

    public static Protocol485Dto getDeviceMonitorInfo(Protocol485Dto protocol485Dto) {
       return context.get().getProtocol485Dto();
    }


}
